//
//  ViewController.m
//  Git
//
//  Created by mac on 16/6/24.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "ViewController.h"
#import "People.h"
@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
{
    UITableView * _tab;
}

@property(nonatomic,strong)NSMutableArray * goups;
@end

@implementation ViewController
-(NSMutableArray *)goups
{
    if (_goups==nil)
    {
        _goups=[[NSMutableArray alloc]init];
    }
    
    return _goups;
}
- (void)viewDidLoad {
    [super viewDidLoad];
   
    
    
    
    [self setUpGoup1];
    [self setUpGoup2];
    [self setUpGoup3];
    /**
     3组 每组几行显示在tableView上
     */
    
    
    _tab = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width,  self.view.bounds.size.height) style:UITableViewStyleGrouped];
    
    _tab.delegate = self;
    _tab.dataSource = self;
    
    [self.view addSubview:_tab];
    
    
    
    
  
    
    
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.goups.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSArray * arr=self.goups[section];
    
    return arr.count;
}
-(UITableViewCell * )tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell)
    {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
    }
    
    NSArray * arr=self.goups[indexPath.section];
    People * P=arr[indexPath.row];
    cell.textLabel.text=P.name;
    cell.detailTextLabel.text=P.age;
    
    
    return cell;
}

-(void)setUpGoup1
{
    People * p=[People name:@"陈佳发" age:@"20"];
    NSArray * arr=@[p];
    [self.goups addObject:arr];
}

-(void)setUpGoup2
{
    
    
    People * p=[People name: @"陈佳发" age:@"20"];
    People * p1=[People name:@"陈佳发" age:@"20"];
    People * p2=[People name:@"陈佳发" age:@"20"];
    People * p3=[People name:@"陈佳发" age:@"20"];
    NSArray * arr=@[p,p1,p2,p3];
    [self.goups addObject:arr];
   
}
-(void)setUpGoup3
{
    
    People * p1=[People name:@"陈佳发" age:@"20"];
    People * p2=[People name:@"陈佳发" age:@"500"];
    People * p3=[People name:@"陈佳发" age:@"20"];
    People * p4=[People name:@"陈佳发" age:@"20"];
    People * p5=[People name:@"陈佳发" age:@"20"];
    NSArray * arr=@[p1,p2,p3,p4,p5];
    [self.goups addObject:arr];
    
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    if (section==0)
    {
        return @"设置";
    }else if (section==1)
    {
        return @"我";
    }else
    {
        return @"版本号";
    }
    
}
@end
